﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class AndroidUtil
{
    private AndroidJavaObject context;
    private AndroidJavaObject map;

    public AndroidUtil(GameObject go, string callback)
    {
        try
        {
            map = new AndroidJavaObject("com.amap.locationservicedemo.MapSDKUtils", go.name, callback);
        }
        catch (Exception e)
        {
            Console.WriteLine("{0} Exception caught.", e);
        }
    }

    public AndroidJavaObject GetContext()
    {
        if (context == null)
        {
            AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            context = jc.GetStatic<AndroidJavaObject>("currentActivity");
        }
        return context;
    }

    public void StartLocation()
    {
        if (map != null)
        {
            Debug.Log("AndroidUtil  ===>>>  StartLocation");
            map.Call("startLocationService");
        }
    }

    public void StopLocation()
    {
        if (map != null)
        {
            Debug.Log("AndroidUtil  ===>>>  StopLocation");
            map.Call("stopLocationService");
        }
    }

    public void Destroy()
    {
        map.Call("Destroy");
    }
}
